package com.ruoyi.project.good.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.good.domain.GoodsPhoto;
import com.ruoyi.project.good.service.IGoodsPhotoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品图片Controller
 * 
 * @author ruoyi
 * @date 2020-07-01
 */
@RestController
@RequestMapping("/good/photo")
public class GoodsPhotoController extends BaseController
{
    @Autowired
    private IGoodsPhotoService goodsPhotoService;

    /**
     * 查询商品图片列表
     */
    @PreAuthorize("@ss.hasPermi('good:photo:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsPhoto goodsPhoto)
    {
        startPage();
        List<GoodsPhoto> list = goodsPhotoService.selectGoodsPhotoList(goodsPhoto);
        return getDataTable(list);
    }

    /**
     * 导出商品图片列表
     */
    @PreAuthorize("@ss.hasPermi('good:photo:export')")
    @Log(title = "商品图片", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GoodsPhoto goodsPhoto)
    {
        List<GoodsPhoto> list = goodsPhotoService.selectGoodsPhotoList(goodsPhoto);
        ExcelUtil<GoodsPhoto> util = new ExcelUtil<GoodsPhoto>(GoodsPhoto.class);
        return util.exportExcel(list, "photo");
    }

    /**
     * 获取商品图片详细信息
     */
    @PreAuthorize("@ss.hasPermi('good:photo:query')")
    @GetMapping(value = "/{photoId}")
    public AjaxResult getInfo(@PathVariable("photoId") Long photoId)
    {
        return AjaxResult.success(goodsPhotoService.selectGoodsPhotoById(photoId));
    }

    /**
     * 新增商品图片
     */
    @PreAuthorize("@ss.hasPermi('good:photo:add')")
    @Log(title = "商品图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsPhoto goodsPhoto)
    {
        return toAjax(goodsPhotoService.insertGoodsPhoto(goodsPhoto));
    }

    /**
     * 修改商品图片
     */
    @PreAuthorize("@ss.hasPermi('good:photo:edit')")
    @Log(title = "商品图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsPhoto goodsPhoto)
    {
        return toAjax(goodsPhotoService.updateGoodsPhoto(goodsPhoto));
    }

    /**
     * 删除商品图片
     */
    @PreAuthorize("@ss.hasPermi('good:photo:remove')")
    @Log(title = "商品图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{photoIds}")
    public AjaxResult remove(@PathVariable Long[] photoIds)
    {
        return toAjax(goodsPhotoService.deleteGoodsPhotoByIds(photoIds));
    }
}
